/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amit.collections;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author amit
 */
public class Serialize {

    public static boolean writeObject(Object toWrite, String path) {
        try {
            ObjectOutputStream objStream = new ObjectOutputStream(new FileOutputStream(path));
            objStream.writeObject(toWrite);
            objStream.flush();
            objStream.close();
            return true;
        } catch (IOException ex) {
            Logger.getLogger(Serialize.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    
    public static Object readObject(String path) {
        try {
            ObjectInputStream objStream = new ObjectInputStream(new FileInputStream(path));
            Object toReturn;
            toReturn = objStream.readObject();
            return toReturn;
        } catch (IOException ex) {
           System.out.println(ex.getMessage());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Serialize.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
